package cn.smart.tokenx.config;

import cn.hutool.core.util.StrUtil;
import cn.smart.tokenx.interceptors.TokenInterceptor;
import cn.smart.tokenx.properties.TokenXProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private TokenXProperty tokenXProperty;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterceptor(tokenXProperty.getKey()))
                .addPathPatterns(tokenXProperty.getPathPatterns()) // 拦截所有api开头的接口请求
                .excludePathPatterns(StrUtil.split(tokenXProperty.getExcludePathPatterns(),",")) ///白名单
                .order(1);
    }
}
